(:
  A procedure to select the contents of the "chat" interventions
:)
declare boundary-space strip;

import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;

let $doc := doc($arguments[1])
let $corpusdoc := doc($arguments[4])
let $isdrew := $arguments[2] = "Drew"
let $starttime := if ($isdrew) then
		$doc/trace/event[1]/time/date
	else
		$doc//record[1]//@millis
let $endtime := if ($isdrew) then
		$doc/trace/event[last()]/time/date
	else
		$doc//record[last()]//@millis
		
return
<display>{
  for $item in $corpusdoc/display/item 
  	where
  		$item/info[@name="type"]/text() = "meta" 
  		or
  		$item/info[@name="filename"]/text() != fn:concat("tracefiles/",$arguments[3]) 
  	return $item, 
  <item>
    <info name="type">{if ($isdrew) then "forestxml" else "xml"}</info>
    <info name="filename">tracefiles/{$arguments[3]}</info>
    <info name="replayer">{$arguments[2]}</info>
    <info name="firsttime">{xs:string($starttime[1])}</info>
    <info name="lasttime">{xs:string($endtime[1])}</info>
    <info name="delta">0</info>
  </item>
}</display>
